#include "CRunServer.h"
#include "ui_CRunServer.h"
#include <QHostAddress>
#include<QCloseEvent>
CRunServer::CRunServer(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::CRunServer)
{
    server=0;
    ui->setupUi(this);
    connect(ui->pushButtonLaunche,SIGNAL(clicked(bool)),this,SLOT(onLaunche()));
}

CRunServer::~CRunServer()
{
    delete ui;
}

void CRunServer::onLaunche()
{
    if(server)
    {
        setWindowTitle(" server is running!");
        return;
    }
    QString host=ui->lineEditHost->text().trimmed();
    QString port=ui->lineEditPort->text().trimmed();
    if(host.isEmpty()||port.isEmpty())
    {
        setWindowTitle("Host or port is empty!");
        return;
    }
    QHostAddress add(host);
    if(!server)
    {
        server=new CChatServer(add,port.toInt(),this);
    }
    close();
}

void CRunServer::closeEvent(QCloseEvent *event)
{
    event->ignore();
    this->hide();
}
